<?php
namespace App\Http\Controllers\Api\Mall;

use App\Http\Controllers\Controller;
use App\UserCoin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class IndexController extends Controller 
{
    /**
     * @function 轮播图
     *
     * @param Request $request
     * @return $this
     */
	public function rotation( Request $request )
	{
		$banner = [
            ['img' => 'http://xy-cdn.oss-cn-hangzhou.aliyuncs.com/xywy/lunbo4.jpg', 'url' => '/zghpt/vip/page'],
			['img' => 'http://xy-cdn.oss-cn-hangzhou.aliyuncs.com/xywy/lunbo5.jpg', 'url' => '/mall/guoji'],
            ['img' => 'http://xy-cdn.oss-cn-hangzhou.aliyuncs.com/xywy/lunbo2.jpg', 'url' => '/wolf'],
		];

		$data['banner'] = $banner;

		return response()->json( ['code' => 1000, 'msg' => 'ok', 'data' => $data] )->withCallback($request->input('callback'));
	}

    /**
     * @function 传送带
     *
     * @param Request $request
     * @return $this
     */
	public function carousel( Request $request )
	{
        $datas = Cache::remember('mall_index_carousel', 1, function () {
            $logs = UserCoin::where('bussiness_id', '>', 0)
                ->whereIn('type', [2])
                ->where('coin', '>', 0)
                ->orderBy('id', 'desc')
                ->take(100)
                ->get();

            $datas = [];
            foreach ($logs as $log) {
                $datas[] = [
                    'nickname' => $log->user->nickname,
                    'description' => $log->desc,
                    'coin'		=> $log->coin
                ];
            }
            return $datas;
        });

		return response()->json(['code' => 1000, 'data' => $datas])->withCallback($request->input('callback'));
	}

    /**
     * @function 底部菜单栏
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function foot(Request $request)
    {
        $data = [];

        $data['foots'] = [
            ['name' => '广场', 'icon' => '/app/tabbar_square@2x.png', 'url' => '/mall'],
            ['name' => '聚宝盆', 'icon' => '/app/tabbar_jbp@2x.png', 'url' => '/jbp/page'],
            ['name' => '我的', 'icon' => '/app/tabbar_mine@2x.png', 'url' => '/user/usercenter'],
        ];

        return response()->json(['code' => 1000, 'data' => $data])->withCallback($request->input('callback'));
    }
}